#ifndef WIDGETBOXCATEGORYMODEL_H
#define WIDGETBOXCATEGORYMODEL_H

#include <QAbstractListModel>
#include <QListView>
#include "category.h"

struct WidgetBoxCategoryEntry {
    WidgetBoxCategoryEntry();
    explicit WidgetBoxCategoryEntry(const Widget &widget,
                                    const QIcon &icon,
                                    bool editable);

    Widget widget;
    QIcon icon;
    bool editable;
};

class WidgetBoxCategoryModel: public QAbstractListModel
{
public:
    explicit WidgetBoxCategoryModel(QObject *parent = 0);

    virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
    virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
    virtual Qt::ItemFlags flags (const QModelIndex & index ) const;

    // The model returns no text in icon mode, so, it also needs to know it
    QListView::ViewMode viewMode() const;
    void setViewMode(QListView::ViewMode vm);

    void addWidget(const Widget &widget, const QIcon &icon, bool editable);

    Widget widgetAt(const QModelIndex & index) const;
    Widget widgetAt(int row) const;

    int indexOfWidget(const QString &name);

    Category category() const;

private:
    typedef QList<WidgetBoxCategoryEntry> WidgetBoxCategoryEntrys;
    WidgetBoxCategoryEntrys m_items;
    QListView::ViewMode m_viewMode;
};

#endif // WIDGETBOXCATEGORYMODEL_H
